//
//  WKCellModel.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-8-5.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKStatusFrame.h"
#import "WKResult.h"

@implementation WKStatusFrame
- (void)setResult:(WKResult *)result
{
    _result = result;
    //间距
    CGFloat mgr = 10;
    
    //1,设置图像的frame
    CGFloat iconX = 10;
    CGFloat iconY = 10;
    CGFloat iconW = 40;
    CGFloat iconH = 40;
    self.iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    //2,设置昵称frame
    CGFloat nameX = CGRectGetMaxX(self.iconFrame) + mgr;
    CGFloat nameY = iconY;
    CGFloat nameW = 100;
    CGFloat nameH = 20;
    self.nameFrame = CGRectMake(nameX, nameY, nameW, nameH);
    
    //3,设置时间的frame
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.nameFrame);
    CGFloat timeW = 200;
    CGFloat timeH = 20;
//    CGFloat tiemMaxW = WKScreenW - 2*iconX;
//    CGSize timeSize = [self.result.passtime sizeWithFont:[UIFont systemFontOfSize:10] constrainedToSize:CGSizeMake(tiemMaxW, MAXFLOAT)];
    
    self.timeFrame = CGRectMake(timeX, timeY, timeW, timeH);
//    self.timeFrame = (CGRect){{timeX,timeY},timeSize};
    
    //4,设置正文的frame
    CGFloat textX = iconX;
    CGFloat textY = CGRectGetMaxY(self.timeFrame) + mgr;
    
    //根据普通文本计算正文的范围
    CGFloat maxW = WKScreenW - 2*iconX;
    CGSize textSize = [self.result.text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(maxW, MAXFLOAT)];
    self.textFrame = (CGRect){{textX,textY},textSize};
    
    //5,设置图片的frame
    CGFloat imageX = mgr;
    CGFloat imageY = CGRectGetMaxY(self.textFrame) + mgr;
    CGFloat imageW = WKScreenW - 2 * mgr;
    CGFloat imageH = 0;
    if (result.height.doubleValue >= WKScreenW){
        imageH = (480/result.width.doubleValue) * imageW;
    }else
    {
        imageH = (result.height.doubleValue/result.width.doubleValue) * imageW;
    }
    self.imageFrame = CGRectMake(imageX, imageY, imageW, imageH);
    
    //5,工具条的frame
    
    CGFloat toolbarX = 0;
    CGFloat toolbarY = CGRectGetMaxY(self.imageFrame) + mgr;
    CGFloat toolbarW = WKScreenW;
    CGFloat toolbarH = 30;
    self.toobaeFrame = CGRectMake(toolbarX, toolbarY, toolbarW, toolbarH);
    
    //5,设置cell的高度
    self.cellHeigth = CGRectGetMaxY(self.toobaeFrame) + 2*mgr;

}
@end
